{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3e3fe220",
   "metadata": {},
   "source": [
    "### *2023.10.11\n",
    "\n",
    "*课程：python语言\n",
    "\n",
    "*week04"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "12c27d30",
   "metadata": {},
   "source": [
    "# 一.本周内容\n",
    " ## 1.数值\n",
    " ## 2.字符串\n",
    " ## 3.range()函数\n",
    " ## 4.for循环"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4a89604d",
   "metadata": {},
   "source": [
    "# 1.数值\n",
    ">1.[数值的概念—Python教程](https://docs.python.org/zh-cn/3/tutorial/introduction.html#numbers)\n",
    "\n",
    ">2.[数值的总结—python参考](https://docs.python.org/zh-cn/3/library/stdtypes.html#built-in-types)\n",
    "\n",
    ">3.数值的分类（type）\n",
    "\n",
    ">>1.int\n",
    "\n",
    ">>2.float\n",
    "\n",
    ">>3.complex"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "afd2e62b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2+2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e92d2eb0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17// 3 #取整"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "74e9771c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17% 3 #取余"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "45b4af46",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "5**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "5f6ff880",
   "metadata": {},
   "outputs": [],
   "source": [
    "width=20\n",
    "height=45"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "c2ffd8fc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "900"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "width*height"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b36ca77b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数值的方法\n",
    "abs(-8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "626a813c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数值的方法\n",
    "abs(-8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "41da2fef",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数值类型\n",
    "a=2023"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "62832726",
   "metadata": {},
   "outputs": [],
   "source": [
    "#type(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "475b274f",
   "metadata": {},
   "outputs": [],
   "source": [
    "pi=3.1415926"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "3dec231b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "float"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(pi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "5267c85e",
   "metadata": {},
   "outputs": [],
   "source": [
    "b=3+2j"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "30c9a000",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "complex"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(b)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fc31f1f9",
   "metadata": {},
   "source": [
    "## 2.字符串\n",
    "\n",
    ">1.字符串的概念和形态\n",
    "\n",
    ">2.字符串的一般方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "9c31fbf8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'span eggs'"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"span eggs\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "8647893e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'paris ruabbit got your back :)! Yay!'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"paris ruabbit got your back :)! Yay!\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d0242a1e",
   "metadata": {},
   "source": [
    "*笔记：如果引号里面是数值，其结果仍为字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "a7483c54",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1975'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'1975'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "17ef20ed",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type('1975')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "6d329fa2",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "unterminated string literal (detected at line 1) (3578565646.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Cell \u001b[1;32mIn[26], line 1\u001b[1;36m\u001b[0m\n\u001b[1;33m    'doesn't'\u001b[0m\n\u001b[1;37m            ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m unterminated string literal (detected at line 1)\n"
     ]
    }
   ],
   "source": [
    "'doesn't'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "25bed5c5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "6cfdf9a2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串的重要特征：序列\n",
    "地址=\"广州市从化区温泉大道882号广州南方学院\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "598f4657",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州市从化区温泉大道882号广州南方学院'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "2be7fe46",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 序列实践\n",
    "#序列：自然数顺序从左到右依次排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "59c5e0c2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[0]# 取值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "6de5f6e6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'市从化'"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[2:5]# 切片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5560b15f",
   "metadata": {},
   "outputs": [],
   "source": [
    "地址[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "31b022be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'学院'"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#请用负数取出来\"学院\"\n",
    "地址[-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "fae20aea",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址.count(\"广州\")#查询数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "366bacbc",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 通过上面的方法尝试输出\"温泉大道\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "22a58fe8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'温泉大道'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[6:10]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d1bd7745",
   "metadata": {},
   "source": [
    "##  3. for循环和range()方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fc010364",
   "metadata": {},
   "source": [
    "* 笔记：range()可以确定范围，并且决定for循环的次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "52b550c8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广\n",
      "州\n",
      "市\n",
      "从\n",
      "化\n",
      "区\n",
      "温\n",
      "泉\n",
      "大\n",
      "道\n",
      "8\n",
      "8\n",
      "2\n",
      "号\n",
      "广\n",
      "州\n",
      "南\n",
      "方\n",
      "学\n",
      "院\n"
     ]
    }
   ],
   "source": [
    "# 把如下操作称为：循环遍历\n",
    "地址=\"广州市从化区温泉大道882号广州南方学院\"\n",
    "for item in 地址:\n",
    "    print(item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "218da320",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range(5):\n",
    "    print (i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2881a010",
   "metadata": {},
   "source": [
    "## for 循环实践"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8ed10f7d",
   "metadata": {},
   "source": [
    "### 实践一： 创建学号 \n",
    "\n",
    "### 增加条件判断，优化学号"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "a2815ea2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "20230103101\n",
      "20230103102\n",
      "20230103103\n",
      "20230103104\n",
      "20230103105\n",
      "20230103106\n",
      "20230103107\n",
      "20230103108\n",
      "20230103109\n",
      "20230103010\n",
      "20230103011\n",
      "20230103012\n",
      "20230103013\n",
      "20230103014\n",
      "20230103015\n",
      "20230103016\n",
      "20230103017\n",
      "20230103018\n",
      "20230103019\n",
      "20230103020\n",
      "20230103021\n",
      "20230103022\n",
      "20230103023\n",
      "20230103024\n",
      "20230103025\n",
      "20230103026\n",
      "20230103027\n",
      "20230103028\n",
      "20230103029\n",
      "20230103030\n",
      "20230103031\n",
      "20230103032\n",
      "20230103033\n",
      "20230103034\n",
      "20230103035\n",
      "20230103036\n",
      "20230103037\n",
      "20230103038\n",
      "20230103039\n",
      "20230103040\n",
      "20230103041\n",
      "20230103042\n",
      "20230103043\n",
      "20230103044\n",
      "20230103045\n",
      "20230103046\n",
      "20230103047\n",
      "20230103048\n",
      "20230103049\n",
      "20230103050\n",
      "20230103051\n",
      "20230103052\n",
      "20230103053\n",
      "20230103054\n",
      "20230103055\n",
      "20230103056\n",
      "20230103057\n",
      "20230103058\n",
      "20230103059\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,60):\n",
    "    # print(i)\n",
    "    if i>9:\n",
    "    print(\"202301030\"+ str(i))\n",
    "    else :\n",
    "        print(\"2023010310\"+str(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b55016c5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
